package com.wang.common.util;

import java.io.InputStream;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
import java.util.ResourceBundle;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.wang.pojo.ASensitiveWords;

/**
 * 存储的是常量
 * 
 * @author Zjx
 */
public class ConstatFinalUtil
{
	/* 定义日志对象 */
	public static final Logger SYS_LOGGER = LogManager.getLogger();
	
	/* 所有的字符串 */
	public static final String ALLSTR = "abcdefghjkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789";

	/**
	 * 参数是配置文件的名字,不能加扩展名
	 */
	public static ResourceBundle SYS_BUNDLE = ResourceBundle.getBundle("system");
	
	/* 编码 */
	public static final String CHARSET = "UTF-8";
	/* 批处理大小，10w */
	public static final int BATCH_SIZE = 1000;
	/**
	 * 固定验证码
	 */
	public static final String RAND_STR = "0715";
	/* 日期的默认格式 */
	public static final String DATE_FORMAT = "yyyy-MM-dd";
	/* 日期时间的默认格式 */
	public static final String DATETIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
	/* io工具类 */
	private static IoUtil ioUtil = new IoUtil();
	/* 放到一个配置类里面 */
	public static JSONObject SYSTEM_JSON = new JSONObject();
	public static JSONObject INFO_JSON = new JSONObject();
	public static JSONObject CONFIG_JSON = new JSONObject();
	
	/* 黑名单 */
	public static final Map<String,ASensitiveWords> HMD_SENSTIVE_MAP = new HashMap<String, ASensitiveWords>();
	/* url */
	public static final Map<String,ASensitiveWords> URL_SENSTIVE_MAP = new HashMap<String, ASensitiveWords>();
	
	/* 存放所有线程的容器 */
	public static Map<String, Map<String, Object>> THREAD_MAP = new Hashtable<String, Map<String, Object>>();

	static
	{
		/* 日期格式化的问题 */
		JSON.DEFFAULT_DATE_FORMAT = DATETIME_FORMAT;

		/*
		 * 读取config.json的文件内容 从classpath中读取一个文件的内容，返回值是一个二进制流
		 */
		InputStream is = ConstatFinalUtil.class.getClassLoader().getResourceAsStream("config.json");
		String result = ioUtil.readContent(is);
		// System.out.println("====" + result);
		SYSTEM_JSON = JSON.parseObject(result);
		// System.out.println("====" + CONFIG_JSON);
		INFO_JSON = SYSTEM_JSON.getJSONObject("info");
		/* 配置json */
		CONFIG_JSON = SYSTEM_JSON.getJSONObject("config");
	}

	public static void main(String[] args)
	{
		ResourceBundle sYS_BUN = ConstatFinalUtil.SYS_BUNDLE;
		String res = ConstatFinalUtil.CONFIG_JSON.get("code.str") + "";
		System.out.println("===" + res);
	}
}
